﻿using Models;
using System.Data.SqlClient;

namespace VirtualGameDAL
{
    public static partial class WeaponService
    {
        public static Weapon GetWeaponById(int id)
        {
            string sql = "SELECT * FROM Weapon WHERE id = @id";
            using (SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@id", id)))
            {
                if (reader.Read())
                {
                    Weapon weapon = new Weapon();
                    weapon.Id = (int)reader["id"];
                    weapon.Name = (string)reader["name"];
                    weapon.Type = (int)reader["type"];
                    weapon.Grade = (int)reader["grade"];
                    weapon.Atk = (int)reader["atk"];
                    weapon.Defense = (int)reader["defense"];
                    weapon.Luck = (int)reader["luck"];
                    reader.Close();
                    return weapon;
                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
        }
    }
}
